/* 
 * Quechua - the lightweight data mining framework
 *
 * Copyright (C) 2012 Marek Denis <quechua@octogan.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef APRIORI_H
#define APRIORI_H

#include <deque>
#include <algorithm>
#include "../../../include/types.h"
#include "../../../include/interface-algorithm.h"
#include "../../../include/interface-common.h"

#include "../../data/indextransactions.h"
#include "../../data/itemsets.h"

// + sth else
using std::deque;

class Apriori : public Algorithm {
 public:
    Apriori();
    virtual ~Apriori();

    bool reset();
    void clear();
    
    datapack_ptr work(datapack_ptr data);
    bool load_misc_conf(const setting_t& misc);
 protected:
    void generate_1_itemsets(IndexTransactions* transactions);
    itemsets* apriorigen(const itemsets* isets);
    void apriori(IndexTransactions* transactions);
    void setupcounters(itemsets* ck,IndexTransactions* tr);
    itemsets* checktransactions(itemsets* ck, itemset* txn);
    bool prunable(itemset* cand,const itemsets* ref);
    static void delitem(itemsets* i);
    // debug functions
    void debug_work();

    int minsup;
    deque<itemsets*> sets;
    
};

extern "C" Algorithm* create_algorithm() {
    return new Apriori();
}

#endif // APRIORI_H
